package leetcode.shuangpoint;

/**
 给定一个非负整数c，你要判断是否存在两个整数 a 和 b，使得a2 + b2 = c 。

 输入：c = 5
 输出：true
 解释：1 * 1 + 2 * 2 = 5

 */
public class JudgeSquareSum633 {
    public static void main(String[] args) {
        System.out.println(new JudgeSquareSum633().judgeSquareSum(2147483600));
    }

    public boolean judgeSquareSum(int c) {
        long i=0;
        long j=(long) Math.sqrt(c);
        while (i<=j){
            long v = i * i + j * j;
            if(v>c)
                j--;
            else if(v<c)
                i++;
            else
                return true;
        }
        return  false;
    }
}